<?php

include_once 'connection/connection_database.php';

class Pages {

    function FillAll($board) {
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and cb.board_id = {$board} and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FindAllLimit(){
        $sql = "SELECT * FROM cate_board_page WHERE page_status = 1 ORDER BY page_id DESC LIMIT 10";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FindAll($tag, $page_id) {
        $sql = "SELECT * FROM cate_board_page WHERE page_tag LIKE '%{$tag}%' and page_id <> {$page_id} and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillPageNew(){
        $sql = "SELECT * FROM cate_board_page WHERE page_status = 1 ORDER BY page_id DESC LIMIT 20";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillAllByHotNews() {
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and page_hotnews=1 and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillOne($board) {
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and cb.board_id = {$board} and page_showhome=1 and page_status = 1 ORDER BY page_id DESC LIMIT 1";
        $result = mysql_query($sql) or die(mysql_error());
        return mysql_fetch_array($result);
    }
    
    function FillByBoard($board_id) {
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and cb.board_id = {$board_id} and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillByCategories($category){
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and c.category_id = {$category} and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillByTitle($page_title) {
        $sql = "SELECT * FROM cate_board_page WHERE page_title LIKE '%{$page_title}%' and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillOneByBoard($board_id, $page_id) {
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and cb.board_id = {$board_id} and cb.page_id <> {$page_id} and page_status = 1 LIMIT 6";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillByCategory($category){
        $sql = "SELECT * FROM cate_board_page cb, cate_board c, category ct WHERE cb.board_id=c.board_id and c.category_id = ct.category_id and c.category_id = {$category} and page_status = 1 ORDER BY cb.page_date DESC LIMIT 10";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillByPageLink($link){
        $sql = "SELECT * FROM cate_board_page WHERE page_link='{$link}' and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
        
    function FillByPageTags($tags){
        $sql = "SELECT * FROM cate_board_page WHERE page_tag LIKE '%{$tags}%' and page_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function UpdatePageCounter($page_id, $page_counter){
        $count = $page_counter+1;
        $sql = "UPDATE cate_board_page SET page_counter='{$count}' WHERE page_id='{$page_id}'";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
}

?>
